package com.mb.fabric.hongda.finance.utils;

import com.alibaba.fastjson.JSONArray;
import com.mb.fabric.hongda.finance.constant.DateConsts;

import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: hongda
 * @description:
 * @author: wys1890
 * @create: 2021-01-26 10:52
 **/
public final class DateTimeUtils {
    
    // 设置星期一为一周开始
    public static final WeekFields WEEK_FIELDS = WeekFields.of(DayOfWeek.MONDAY, 1);
    
    // 时间格式校验
    public static final String CHECK_FORMAT = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01]) ([01]?[0-9]|2[0-3]):[0-5]?[0-9]:[0-5]?[0-9]";
    
    private static final HashMap<Integer, String> WEEK = new HashMap<>(16);
    
    
    static {
        /*周转换**/
        WEEK.put(1, "周一");
        WEEK.put(2, "周二");
        WEEK.put(3, "周三");
        WEEK.put(4, "周四");
        WEEK.put(5, "周五");
        WEEK.put(6, "周六");
        WEEK.put(7, "周日");
        
        
    }
    
    public static final String PATTERN_DATE = "yyyy-MM-dd HH:mm:ss";
    
    public static final String PATTERN_YYYY_MM_DD = "yyyy-MM-dd";
    
    public static final String PATTERN_YYYY_MM = "yyyy-MM";
    
    //东八区
    public static final ZoneId CHINA_ZONE_ID = ZoneId.of("Asia/Shanghai");
    
    public static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder()
            .appendPattern(PATTERN_DATE)
            .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
            .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
            .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
            .toFormatter()
            .withZone(CHINA_ZONE_ID);
    
    public static final DateTimeFormatter YYYY_MM_DD = new DateTimeFormatterBuilder()
            .appendPattern(PATTERN_YYYY_MM_DD)
            .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
            .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
            .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
            .toFormatter()
            .withZone(CHINA_ZONE_ID);
    
    public static final DateTimeFormatter YYYY_MM = new DateTimeFormatterBuilder()
            .appendPattern(PATTERN_YYYY_MM)
            .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
            .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
            .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
            .toFormatter()
            .withZone(CHINA_ZONE_ID);
    
    
    /**
     * @return : java.time.ZonedDateTime
     * @Description : 当前时间
     * @author Eibons
     * @date 2021/1/26 13:36
     */
    public static ZonedDateTime now() {
        return ZonedDateTime.of(LocalDateTime.now(), CHINA_ZONE_ID);
    }
    
    /**
     * @param dateString : 比较时间
     * @return : boolean
     * @Description : 是否比当前早
     * @author Eibons
     * @date 2021/1/26 13:36
     */
    public static boolean isNowBefore(String dateString) {
        ZonedDateTime time = ZonedDateTime.of(LocalDateTime.parse(dateString, FORMATTER), CHINA_ZONE_ID);
        return now().isBefore(time);
    }
    
    /**
     * @param dateString : 比较时间
     * @return : boolean
     * @Description : 是否比当前晚
     * @author Eibons
     * @date 2021/1/26 13:36
     */
    public static boolean isNowAfter(String dateString) {
        ZonedDateTime time = ZonedDateTime.of(LocalDateTime.parse(dateString, FORMATTER), CHINA_ZONE_ID);
        return now().isAfter(time);
    }
    
    /**
     * @param dateStr      : 时间A
     * @param otherDateStr : 时间B
     * @return : int
     * @Description : 两个时间比较
     * @author Eibons
     * @date 2021/1/26 13:36
     */
    public static int compareTo(String dateStr, String otherDateStr) {
        ZonedDateTime dateTime = ZonedDateTime.of(LocalDateTime.parse(dateStr, FORMATTER), CHINA_ZONE_ID);
        ZonedDateTime otherDateTime = ZonedDateTime.of(LocalDateTime.parse(otherDateStr, FORMATTER), CHINA_ZONE_ID);
        return dateTime.compareTo(otherDateTime);
    }
    
    /**
     * 获取当月的第几号 2020-01-10 -> 10
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static int getDayValueOfMonth(String dateStr) {
        return parse(dateStr).getDayOfMonth();
    }
    
    /**
     * 获取当月的第几号 2020-01-10 -> 10
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.Integer
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static String getDayStrOfMonth(String dateStr) {
        int dayOfMonth = getDayValueOfMonth(dateStr);
        return dayOfMonth < 10 ? "0" + dayOfMonth : String.valueOf(dayOfMonth);
    }
    
    
    /**
     * 获取当年的第几周
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.Integer
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static int getWeekValueOfBasedYear(String dateStr) {
        return parse(dateStr).get(WEEK_FIELDS.weekOfWeekBasedYear());
    }
    
    /**
     * 获取当月的第几周
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.Integer
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static int getWeekValueOfBasedMonth(String dateStr) {
        return parse(dateStr).get(WEEK_FIELDS.weekOfMonth());
    }
    
    /**
     * 获取月份 2020-01-10 -> 1
     *
     * @param dateStr :日期字符串
     * @return : java.lang.Integer
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static int getMonthValue(String dateStr) {
        return parse(dateStr).getMonthValue();
    }
    
    /**
     * 获取月份 2020-01-10 -> 01
     *
     * @param dateStr :日期字符串
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static String getMonthStr(String dateStr) {
        int monthValue = getMonthValue(dateStr);
        return getMonthValue(dateStr) < 10 ? "0" + monthValue : String.valueOf(monthValue);
    }
    
    /**
     * 日期属于第几季度
     *
     * @param dateStr :日期字符串
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/5/11 11:05
     */
    public static String getQuarterStr(String dateStr) {
        return "第" + getQuarterValue(dateStr) + "季度";
    }
    
    /**
     * 日期属于第几季度
     * <p>
     * 算法解释：
     * 季度是每三月算一个季度，故除以3，
     * java 中 2个整数相除必得整数，是去尾取整法，即:正数向下取整，负数向上取整，也可以理解为逼零取整，
     * 故补1来表示季度数
     *
     * @param dateStr :日期字符串
     * @return : java.lang.Integer
     * @author Eibons
     * @date 2021/5/11 11:05
     */
    public static int getQuarterValue(String dateStr) {
        return (parse(dateStr).getMonthValue() - 1) / 3 + 1;
    }
    
    /**
     * 获取年份 2020-01-10 -> 2020
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.Integer
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static int getYearValue(String dateStr) {
        return parse(dateStr).getYear();
    }
    
    /**
     * 获取年份 2020-01-10 -> 2020
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/2/4 15:34
     */
    public static String getYearStr(String dateStr) {
        return String.valueOf(getYearValue(dateStr));
    }
    
    //*************************************************************//
    
    
    /**
     * 当天零点
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:39
     */
    public static ZonedDateTime getMorningTimeOfDay() {
        return now().withHour(0).withMinute(0).withSecond(0);
    }
    
    /**
     * 当天 23:59:59
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:39
     */
    public static ZonedDateTime getNightTimeOfDay() {
        return now().withHour(23).withMinute(59).withSecond(59);
    }
    
    
    /**
     * 当前周第一天零点
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:39
     */
    public static ZonedDateTime getFirstDayOfWeek() {
        return getMorningTimeOfDay().with(ChronoField.DAY_OF_WEEK, 1);
    }
    
    /**
     * 当前周最后一天 23:59:59
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:39
     */
    public static ZonedDateTime getLastDayOfWeek() {
        return getMorningTimeOfDay().with(ChronoField.DAY_OF_WEEK, 7);
    }
    
    /**
     * 当月第一天 00:00:00
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:39
     */
    public static ZonedDateTime getFirstDayOfMonth() {
        return getMorningTimeOfDay().with(TemporalAdjusters.firstDayOfMonth());
    }
    
    /**
     * 当月最后一天 23:59:59
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:47
     */
    public static ZonedDateTime getLastDayOfMonth() {
        return getNightTimeOfDay().with(TemporalAdjusters.lastDayOfMonth());
    }
    
    /**
     * 当前季度第一天
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:39
     */
    public static ZonedDateTime getFirstDayOfQuarter() {
        return getFirstDayOfQuarter(0);
    }
    
    /**
     * 当前季度最后一天
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:47
     */
    public static ZonedDateTime getLastDayOfQuarter() {
        return getLastDayOfQuarter(0);
    }
    
    /**
     * 前N季度第一天
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:39
     */
    public static ZonedDateTime getFirstDayOfQuarter(int n) {
        // 减去num个季度
        final ZonedDateTime zonedDateTime = getMorningTimeOfDay().minusMonths(n * 3L);
        // 所求那年属于哪一季度
        int lastQuarterNum = zonedDateTime.getMonthValue() / 3 + 1;
        // 获取月数范围的起始值月份
        int month = lastQuarterNum * 3 - 2;
        // 获取月份的第一天
        return zonedDateTime.withMonth(month).with(TemporalAdjusters.firstDayOfMonth());
    }
    
    /**
     * 前N季度最后一天
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/1/27 8:47
     */
    public static ZonedDateTime getLastDayOfQuarter(int n) {
        // 减去num个季度
        final ZonedDateTime zonedDateTime = getNightTimeOfDay().minusMonths(n * 3L);
        // 所求那年属于哪一季度
        int lastQuarterNum = zonedDateTime.getMonthValue() / 3 + 1;
        // 获取月数范围的起始值月份
        int month = lastQuarterNum * 3;
        // 获取月份的最后一天
        return zonedDateTime.withMonth(month).with(TemporalAdjusters.lastDayOfMonth());
    }
    
    /**
     * 当年的第一天
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/2/3 15:53
     */
    public static ZonedDateTime getFirstDayOfYear() {
        return getMorningTimeOfDay().with(TemporalAdjusters.firstDayOfYear());
    }
    
    /**
     * 当年的最后一天
     *
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/2/3 15:53
     */
    public static ZonedDateTime getLastDayOfYear() {
        return getNightTimeOfDay().with(TemporalAdjusters.lastDayOfYear());
    }
    
    /**
     * 转换日期
     *
     * @param dateStr : 日期字符串
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/2/2 18:32
     */
    public static ZonedDateTime parse(String dateStr, DateTimeFormatter formatter) {
        return ZonedDateTime.parse(dateStr, formatter);
    }
    
    /**
     * 转换日期
     *
     * @param dateStr : 日期字符串
     * @return : java.time.ZonedDateTime
     * @author Eibons
     * @date 2021/2/2 18:32
     */
    public static ZonedDateTime parse(String dateStr) {
        return parse(dateStr, FORMATTER);
    }
    
    /**
     * 转换日期格式
     *
     * @param dateStr      : 日期字符串
     * @param oldFormatter : 原来的格式
     * @param newFormatter : 转换后的格式
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/2/5 10:08
     */
    public static String changeFormat(String dateStr, DateTimeFormatter oldFormatter, DateTimeFormatter newFormatter) {
        return ZonedDateTime.parse(dateStr, oldFormatter).format(newFormatter);
    }
    
    /**
     * 将日期转换为时间戳
     *
     * @param dateStr : 日期
     * @return : long
     * @author Eibons
     * @date 2021/2/4 15:01
     */
    public static long dateStr2Timestamp(String dateStr) {
        return parse(dateStr).toEpochSecond();
    }
    
    /**
     * 将时间戳转换为日期
     *
     * @param timestamp : 时间戳
     * @return : long
     * @author Eibons
     * @date 2021/2/4 15:01
     */
    public static String timestamp2DateStr2(long timestamp) {
        return ZonedDateTime.ofInstant(Instant.ofEpochSecond(timestamp), CHINA_ZONE_ID).format(FORMATTER);
    }
    
    /**
     * 获取日期是星期几
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/2/5 10:07
     */
    public static String getWeekDay(String dateStr) {
        return WEEK.get(ZonedDateTime.parse(dateStr, FORMATTER).getDayOfWeek().getValue());
    }
    
    /**
     * 判断日期是否是周末
     *
     * @param dateStr : 日期字符串
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/2/5 10:07
     */
    public static boolean isWeekendDay(String dateStr) {
        int week = ZonedDateTime.parse(dateStr, FORMATTER).getDayOfWeek().getValue();
        return week == 6 || week == 7;
    }
    
    
    /**
     * 根据日周月标记来滑动获取时间窗口范围
     *
     * @param dateFlag 日期单位标记：日周月季年
     * @param offset   日期量：page期数（几天还是几周还是几个月）
     * @return : java.util.Map<java.lang.String,java.time.ZonedDateTime>
     * @author Eibons
     * @date 2021/2/2 18:16
     */
    public static Map<String, ZonedDateTime> slideDateRange(String dateFlag, int offset) {
        HashMap<String, ZonedDateTime> res = new HashMap<>(4);
        ZonedDateTime dateBegin;
        ZonedDateTime dateEnd;
        switch (dateFlag) {
            case DateConsts.DAY_FLAG:
                dateBegin = getMorningTimeOfDay().minusDays(offset);
                dateEnd = getNightTimeOfDay().minusDays(offset);
                break;
            case DateConsts.WEEK_FLAG:
                dateBegin = getFirstDayOfWeek().minusWeeks(offset);
                dateEnd = getLastDayOfWeek().minusWeeks(offset);
                break;
            case DateConsts.MONTH_FLAG:
                dateBegin = getFirstDayOfMonth().minusMonths(offset);
                dateEnd = getLastDayOfMonth().minusMonths(offset);
                break;
            case DateConsts.QUARTER_FLAG:
                dateBegin = getFirstDayOfQuarter(offset);
                dateEnd = getLastDayOfQuarter(offset);
                break;
            case DateConsts.YEAR_FLAG:
                dateBegin = getFirstDayOfYear().minusYears(offset);
                dateEnd = getLastDayOfYear().minusYears(offset);
                break;
            default:
                throw new RuntimeException("传入参数非'日','周','月','季','年'。");
        }
        res.put(DateConsts.DATE_BEGIN, dateBegin);
        res.put(DateConsts.DATE_END, dateEnd);
        return res;
    }
    
    /**
     * 根据日期获取时间的范围
     *
     * @param dateStr : 日期字符串
     * @return :
     * @author Eibons
     * @date 2021/5/19 16:27
     */
    public static Map<String, ZonedDateTime> getDateRangeByDateStr(String dateStr) {
        HashMap<String, ZonedDateTime> res = new HashMap<>(4);
        ZonedDateTime zonedDateTime = parse(dateStr);
        ZonedDateTime dateBegin = zonedDateTime.with(TemporalAdjusters.firstDayOfMonth())
                .withHour(0).withMinute(0).withSecond(0);
        ZonedDateTime dateEnd = zonedDateTime.with(TemporalAdjusters.lastDayOfMonth())
                .withHour(23).withMinute(59).withSecond(59);
        res.put(DateConsts.DATE_BEGIN, dateBegin);
        res.put(DateConsts.DATE_END, dateEnd);
        return res;
    }
    
    /**
     * 根据日周月标记来获取时间的范围
     *
     * @param dateFlag 日期单位标记：日周月季年
     * @author Eibons
     * @date 2021/2/2 18:16
     */
    public static Map<String, ZonedDateTime> getCurrentDateRange(String dateFlag) {
        HashMap<String, ZonedDateTime> res = new HashMap<>(4);
        ZonedDateTime dateBegin;
        ZonedDateTime dateEnd;
        switch (dateFlag) {
            case DateConsts.DAY_FLAG:
                dateBegin = getFirstDayOfMonth();
                break;
            case DateConsts.WEEK_FLAG:
            case DateConsts.MONTH_FLAG:
            case DateConsts.QUARTER_FLAG:
                dateBegin = getFirstDayOfYear();
                break;
            case DateConsts.YEAR_FLAG:
                dateBegin = getFirstDayOfYear().minusYears(2);// 取前3年
                break;
            default:
                throw new RuntimeException("传入参数非'日','周','月','季','年'。");
        }
        dateEnd = getNightTimeOfDay();
        res.put(DateConsts.DATE_BEGIN, dateBegin);
        res.put(DateConsts.DATE_END, dateEnd);
        return res;
    }
    
    /**
     * 根据日周月标记来获取本期数据日期范围和上一期的数据日期范围
     * <p>
     * 注意：数据分组的时候要特别小心，因为数据周的情况中存在这个月的第一周和上个月的最后一周有重合，
     * 所以分组的标记应该是  “年份+月份+月的第几周”
     *
     * @param dateFlag 日期单位标记：日周月季年
     * @return : java.util.Map<java.lang.String,java.time.ZonedDateTime>
     * @author Eibons
     * @date 2021/2/2 18:16
     */
    public static Map<String, ZonedDateTime> getDateRangeWithPrevious(String dateFlag) {
        HashMap<String, ZonedDateTime> res = new HashMap<>(4);
        ZonedDateTime dateBegin;
        ZonedDateTime dateEnd;
        switch (dateFlag) {
            case DateConsts.DAY_FLAG:
                dateBegin = getFirstDayOfMonth().minusDays(1);
                dateEnd = getNightTimeOfDay();
                break;
            case DateConsts.WEEK_FLAG:
                ZonedDateTime firstDayOfMonth = getFirstDayOfMonth();
                int weekDay = firstDayOfMonth.get(WEEK_FIELDS.dayOfWeek());
                dateBegin = firstDayOfMonth.minusDays(7 - weekDay).with(ChronoField.DAY_OF_WEEK, 1);
                dateEnd = getLastDayOfWeek();
                break;
            case DateConsts.MONTH_FLAG:
                dateBegin = getFirstDayOfYear().minusMonths(1);
                dateEnd = getLastDayOfMonth();
                break;
            case DateConsts.QUARTER_FLAG:
                dateBegin = getFirstDayOfYear().minusMonths(3).with(TemporalAdjusters.firstDayOfMonth());
                dateEnd = getLastDayOfQuarter();
                break;
            case DateConsts.YEAR_FLAG:
                dateBegin = getFirstDayOfYear().minusYears(4);
                dateEnd = getLastDayOfYear();
                break;
            default:
                throw new RuntimeException("传入参数非'日','周','月','季','年'。");
        }
        res.put(DateConsts.DATE_BEGIN, dateBegin);
        res.put(DateConsts.DATE_END, dateEnd);
        return res;
    }
    
    
    /**
     * 限定时间范围至当前时间
     *
     * @param dateStr :
     * @return : void
     * @author Eibons
     * @date 2021/2/25 11:06
     */
    public static String limitDateAtCurrentTime(String dateStr) {
        ZonedDateTime zonedDateTime = DateTimeUtils.parse(dateStr);
        ZonedDateTime now = DateTimeUtils.now();
        if (zonedDateTime.isAfter(now)) {
            dateStr = now.format(DateTimeUtils.FORMATTER);
        }
        return dateStr;
    }
    
    /**
     * 按日期类型拆分日期
     *
     * @param dateBegin : 起始日期
     * @param dateEnd   : 结束日期
     * @return : com.alibaba.fastjson.JSONArray
     * @author Eibons
     * @date 2021/5/11 10:40
     */
    public static JSONArray splitDateTime(String dateFlag, String dateBegin, String dateEnd) {
        JSONArray jsonArray = new JSONArray();
        ZonedDateTime begin = parse(dateBegin);
        ZonedDateTime end = parse(dateEnd);
        String endDay;
        switch (dateFlag) {
            case DateConsts.DAY_FLAG:
                while (begin.isBefore(end)) {
                    jsonArray.add(getDayStrOfMonth(begin.format(FORMATTER)));
                    begin = begin.plusDays(1);
                }
                endDay = getDayStrOfMonth(end.format(FORMATTER));
                if (!jsonArray.contains(endDay)) {
                    jsonArray.add(endDay);
                }
                break;
            case DateConsts.WEEK_FLAG:
                while (begin.isBefore(end)) {
                    jsonArray.add("第" + getWeekValueOfBasedMonth(begin.format(FORMATTER)) + "周");
                    begin = begin.plusWeeks(1);
                }
                endDay = "第" + getWeekValueOfBasedMonth(end.format(FORMATTER)) + "周";
                if (!jsonArray.contains(endDay)) {
                    jsonArray.add(endDay);
                }
                break;
            case DateConsts.MONTH_FLAG:
                while (begin.isBefore(end)) {
                    jsonArray.add(getMonthStr(begin.format(FORMATTER)) + "月");
                    begin = begin.plusMonths(1);
                }
                endDay = getMonthStr(end.format(FORMATTER)) + "月";
                if (!jsonArray.contains(endDay)) {
                    jsonArray.add(endDay);
                }
                break;
            case DateConsts.QUARTER_FLAG:
                while (begin.isBefore(end)) {
                    jsonArray.add(getQuarterStr(begin.format(FORMATTER)));
                    begin = begin.plusMonths(3);
                }
                endDay = getQuarterStr(begin.format(FORMATTER));
                if (!jsonArray.contains(endDay)) {
                    jsonArray.add(endDay);
                }
                break;
            case DateConsts.YEAR_FLAG:
                while (begin.isBefore(end)) {
                    jsonArray.add(getYearStr(begin.format(FORMATTER)));
                    begin = begin.plusYears(1);
                }
                endDay = getYearStr(end.format(FORMATTER));
                if (!jsonArray.contains(endDay)) {
                    jsonArray.add(endDay);
                }
                break;
            default:
                throw new RuntimeException("传入参数非'日','周','月','季','年'。");
        }
        return jsonArray;
    }
    
    /**
     * 去除前4位年份
     *
     * @param dateFlag :
     * @param dateStr  :
     * @return : java.lang.String
     * @author Eibons
     * @date 2021/5/11 17:31
     */
    public static String handleDateStr(String dateFlag, String dateStr) {
        String temp = dateStr.substring("yyyy".length());
        switch (dateFlag) {
            case DateConsts.MONTH_FLAG:
                // 月
                temp = temp + "月";
                break;
            case DateConsts.QUARTER_FLAG:
                // 季
                temp = "第" + temp + "季度";
                break;
            case DateConsts.YEAR_FLAG:
                // 年
                temp = temp + "年";
                break;
            default:
                throw new RuntimeException("日期类型参数非法，请输入'月'或'季'或'年'");
        }
        return temp;
    }
    
    
    public static void main(String[] args) {
        
        System.out.println(getCurrentDateRange("日"));
        System.out.println(getCurrentDateRange("周"));
        System.out.println(getCurrentDateRange("月"));
        System.out.println(getCurrentDateRange("季"));
        System.out.println(getCurrentDateRange("年"));
        System.out.println("********************************");
        System.out.println(getDateRangeWithPrevious("日"));
        System.out.println(getDateRangeWithPrevious("周"));
        System.out.println(getDateRangeWithPrevious("月"));
        System.out.println(getDateRangeWithPrevious("季"));
        System.out.println(getDateRangeWithPrevious("年"));
        System.out.println("********************************");
        System.out.println(slideDateRange("日", 3));
        System.out.println(slideDateRange("周", 1));
        System.out.println(slideDateRange("月", 3));
        System.out.println(slideDateRange("季", 2));
        System.out.println(slideDateRange("年", 1));
//        System.out.println(splitDateTime("日", "2021-05-01 00:00:00", "2021-05-11 23:59:59"));
//        System.out.println(splitDateTime("周", "2021-05-01 00:00:00", "2021-05-11 23:59:59"));
//        System.out.println(splitDateTime("月", "2021-01-01 00:00:00", "2021-05-11 23:59:59"));
//        System.out.println(splitDateTime("季", "2021-01-01 00:00:00", "2021-05-11 23:59:59"));
//        System.out.println(splitDateTime("年", "2020-05-01 00:00:00", "2021-05-11 23:59:59"));
    }
}
